package cn.bby.query.base.constant;

import lombok.Getter;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @author ben
 * @since 2025/4/20 00:18
 */
@Getter
public enum ColumnType {
    NUMBER("number", Number.class),
    DECIMAL("decimal", BigDecimal.class),
    STRING("string", String.class),
    DATE("date", Timestamp.class),
    BOOLEAN("boolean", Boolean.class),
    LIST("list", List.class);

    public final String code;
    public final Class<?> javaType;

    ColumnType(String code, Class<?> javaType) {
        this.code = code;
        this.javaType = javaType;
    }

    private static final Map<String, ColumnType> codeMap = Arrays.stream(values())
            .collect(java.util.stream.Collectors.toMap(ColumnType::getCode, Function.identity()));

    public static ColumnType getByCode(String code) {
        return codeMap.get(code);
    }

    public boolean equals(String code) {
        return this.code.equals(code);
    }
}
